package com.example.testapplication.ui.guide;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableList;

import com.example.testapplication.BR;
import com.example.testapplication.R;
import com.example.testapplication.binding.viewPager2.ViewAdapter;
import com.example.testapplication.ui.login.LoginActivity;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.binding.command.BindingConsumer;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;
import me.tatarka.bindingcollectionadapter2.ItemBinding;


public class GuideViewModel extends BaseViewModel {


    public GuideViewModel(@NonNull Application application) {
        super(application);
        for (int i = 0; i < mGuidanceIdList.length; i++) {
            observableList.add(new GuideItemViewModel(GuideViewModel.this, mGuidanceIdList[i]));
        }

    }

    public ObservableField<String> indicator = new ObservableField<>("1/3");

    //封装一个界面发生改变的观察者
    public UIChangeObservable uc = new UIChangeObservable();

    public class UIChangeObservable {
        //viewPager2页面切换
        public SingleLiveEvent pClickEvent = new SingleLiveEvent<>();
    }

    // 引导页
    public int[] mGuidanceIdList = new int[]{R.drawable.guide1, R.drawable.guide2, R.drawable.guide3};

    //给ViewPager2添加ObservableList
    public ObservableList<GuideItemViewModel> observableList = new ObservableArrayList<>();

    //给ViewPager2添加ItemBinding
    public ItemBinding<GuideItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_guide);

    public BindingCommand onPageScrolledCommand = new BindingCommand(new BindingConsumer<ViewAdapter.ScrollDataWrapper>() {

        @Override
        public void call(ViewAdapter.ScrollDataWrapper scrollDataWrapper) {
            uc.pClickEvent.setValue(scrollDataWrapper);
        }
    });

    public BindingCommand onPageScrollStateCommand = new BindingCommand(new BindingConsumer<Integer>() {

        @Override
        public void call(Integer integer) {
            uc.pClickEvent.setValue(integer);
        }
    });

    public BindingCommand onCompleteCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(LoginActivity.class);
            finish();
        }
    });



}
